/*
 * @Author: your name
 * @Date: 2021-09-13 10:48:17
 * @LastEditTime: 2021-09-13 11:43:53
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \team\src\store\modules\talent.js
 */
import {
    addTa,
    taList,
    updateTa,
    seeTa
} from '@/api/talentApi'

export default {
    state: {
        talentList: []
    },
    getters: {
        userInfo(state){
            return (id)=>{
                
               return state.talentList.filter(item => item.contact == id)
               
            }
            
        }
    },
    mutations: {
        getTalentList(state, payload){
            // console.log(state);
            state.talentList = payload
        },
        addTalentList(state, payload){
            // console.log(state.talentList);
            state.talentList = [...state.talentList,payload]
            // console.log(state.talentList);
            
        },
        updateList(state, payload){
            // emmmm
            state.talentList = [...state.talentList,payload]
        }
    },
    actions: {

        // 获取列表
        async taListAction({commit}, page = 1){
            let ret = await taList()
            commit('getTalentList', ret.data.userData)
        },

        //添加人才
        async addTaAction({commit}, talentInfo) {
            // console.log(talentInfo);
            let ret = await addTa(talentInfo)
            // console.log(ret.data.data);
            commit('addTalentList',ret.data.data)
            return ret
        },

        // 修改
        async updateTaAction({commit},talentInfo){
            let ret = await updateTa(talentInfo)
            // console.log(ret.data.data);
            commit('updateList',ret.data.data)
            return ret
        },

        // 查看
        async seeTaAction({commit},talentInfo){
            let ret = await seeTa(talentInfo)

            console.log(ret);
        }
    }
}